<?php
require 'includes/master_include.php';

$user = new user();
if(array_key_exists("user",$_GET)){
	$user = user::get($_GET['user']);
}else if(array_key_exists('user',$_COOKIE)){
	$user = $user = user::get($_COOKIE['user']);
}

if(array_key_exists("submit",$_GET)){
	$user->username = $_GET['user'];
	if(array_key_exists("threshold",$_GET)) $user->threshold = $_GET['threshold'];
	$user->current_cache_guid = uniqid();
	$user->save();
}


if (array_key_exists('refresh',$_GET) || $user->can_refresh()){
	$user->clear_cache();
}

if($user->id > 0){
	setcookie('user',$user->username,time()+60*60*24*30);
}





$tabs = array();
for($i=65;$i<=90;$i++){
	$tabs[] =chr($i);
}
$tabs[] = '1-9';
$tabs[] = '!$&';
//library_cache_artists($user,$cache_guid, 1,10,false);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Spotilibrary - Spotify + your Last.fm library</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

<link type="text/css" href="css/style.css" rel="stylesheet" />
<link rel="stylesheet" href="css/sIFR-screen.css" type="text/css"
	media="screen" />
<link rel="stylesheet" href="css/sIFR-print.css" type="text/css"
	media="print" />


<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script src="js/sifr.js" type="text/javascript"></script>
<script type="text/javascript" src="js/global.js"></script>
<script type="text/javascript">
//<![CDATA[
	$(document).ready(function(){

  		<?php if($user->continue_cache() > 0): ?>
		get_next_page(<?php print $user->current_page+1 ?>,3);
		<?php endif; ?>
		get_home();
		get_next_tags();
		});
		

	//]]>
</script>
</head>
<body>
<div class="container">
<div class="header_left">
<div class="header_right">
<div class="header_center">
<h1><?php if($user->id > 0):?><?php print htmlentities($user->username) ?>'s
<?php else: ?>Welcome to <?php endif; ?>Spotilibrary</h1>
<ul class="header_links">
	<li><a href="faq.php" class="by_ajax">FAQ</a></li>
	<li><a href="about.php" class="by_ajax">About</a></li>
</ul>
</div>
</div>
</div>

<ul class="menu">
<?php foreach($tabs as $i => $tab):?>
	<li class="initial">
	<div class="tab_left">
	<div class="tab_right">
	<div class="tab_center<?php if($i>=26): print ' wider'; endif; ?>"><a
		href="#"><?php print htmlentities($tab) ?></a></div>
	</div>
	</div>
	</li>
	<?php endforeach; ?>

</ul>

<div class="settings_outer">

<div class="settings<?php if($user->id <= 0):?> new_user<?php endif; ?>">
<h2><?php if($user->id <= 0):?>Create your new music library<?php else:?>Setup Your Spotilibrary<?php endif; ?></h2>

<form method="get" action="index.php"><?php if($user->id > 0):?>
<fieldset><legend>Maintenence</legend>
<p>Click below to delete all your data quickly and cleanly. You can
set-up your Spotilibrary again anytime you like.</p>
<input type="submit" value="Delete my data" id="delete"
	name="delete"  class="button"/>
<p>Spotify re-indexes your library on your first visit of the day but if
you have some new music you want to add right now, click below.</p>
<input type="submit" value="Re-index now" id="refresh"
	name="refresh"  class="button"/></fieldset>
	<?php endif; ?>
	</form>
	<?php if($user->id <= 0):?><p>Spotlibrary is here to make your music easier to find in Spotify. 
	Enter your Last.fm username and Spotilibrary will use your profile
	to create a music library organised by artist that links directly into Spotify.</p><?php endif; ?>
	<form method="get" action="index.php">
<fieldset><legend>Settings</legend>
<div><label>Last.fm username:</label><input type="text" name="user"
	value="<?php print $user->username ?>" />
</div>
<!-- 
<div><label>Play count threshold:</label><input type="text"
	name="threshold" maxlength="2" value="<?php print $user->threshold ?>" />
<p>Hide artists you have only played a number of times less than or
equal to this number. Use this to make the size of your Spotilibrary
more manageable. Yu can show the hidden artists at any time.</p>
</div> 
<p>When you click save, Spotilibrary will begin downloading the artists
your Last.fm account has scrobbled. This data is publicly available to via the <a
	href="http://www.last.fm/api">Last.fm API</a>.</p>-->
<div class="submit">

<input type="submit" value="<?php if($user->id <= 0):?>Create!<?php else:?>Save<?php endif; ?>" id="submit" name="submit" class="button"/></div>
</fieldset>
</form>

</div>
<div class="open_settings">
<div class="tab_left">
<div class="tab_right">
<div class="tab_center"><a href="#">Settings</a></div>
</div>
</div>
</div>

</div>
<div class="artists_outer">
<div class="artists"></div>
</div>
<div class="body">
<div class="message">Fetching data</div>
<div class="progress"></div>
<div class="content"></div>

</div>
</div>
<script type="text/javascript">
		//<![CDATA[
		/* Replacement calls. Please see documentation for more information. */


		if(typeof sIFR == "function"){
		sIFR.replaceElement("h1", named({sFlashSrc: "swf/tuffy.swf", sColor: "#FFFFFF", sBgColor: "#000000", sWmode:"transparent"}));
		
			//sIFR.replaceElement(named({sSelector:"h1", sFlashSrc:"swf/old typewriter.swf",sColor:"#FFF", sBgColor:"#333"}));
		// This is the preferred "named argument" syntax
//			sIFR.replaceElement(named({sSelector:"h1", sFlashSrc:"swf/old typewriter.swf"}));
			sIFR.replaceElement(named({sSelector:"h2", sFlashSrc:"swf/tuffy.swf"}));
//			sIFR.replaceElement(named({sSelector:"h3", sFlashSrc:"swf/tradegothic.swf"}));
//			sIFR.replaceElement(named({sSelector:"h4", sFlashSrc:"swf/tradegothic.swf"}));
//			sIFR.replaceElement(named({sSelector:"h5", sFlashSrc:"swf/tradegothic.swf"}));
//			sIFR.replaceElement(named({sSelector:".sifr", sFlashSrc:"swf/tradegothic.swf",sColor:"#ff0000",sBgColor:"#ccccff"}));
		
		}
		//]]>
		</script>


<script type="text/javascript">
		//<![CDATA[
var uservoiceOptions = {
  /* required */
  key: 'spotilibrary',
  host: 'spotilibrary.uservoice.com', 
  forum: '50237',
  showTab: true,  
  /* optional */
  alignment: 'left',
  background_color:'#57B400', 
  text_color: 'white',
  hover_color: '#529002',
  lang: 'en'
};

function _loadUserVoice() {
  var s = document.createElement('script');
  s.setAttribute('type', 'text/javascript');
  s.setAttribute('src', ("https:" == document.location.protocol ? "https://" : "http://") + "cdn.uservoice.com/javascripts/widgets/tab.js");
  document.getElementsByTagName('head')[0].appendChild(s);
}
_loadSuper = window.onload;
window.onload = (typeof window.onload != 'function') ? _loadUserVoice : function() { _loadSuper(); _loadUserVoice(); };
		//]]>
</script>

</body>
</html>
